<?php

require_once(dirname(__FILE__) . '/wap/core.php');

set_time_limit(0);


    $target = $_SERVER['DOCUMENT_ROOT'] . '/area_array.js';

    $buffer = ['var nc_a = [];'];

    $get_next_area = function($pid) use(&$buffer,&$get_next_area){
        $children = ml('area')->select('area_parent_id = ' . $pid);
        $_children = [];
        if ($children) {
            foreach ($children as $child) {
                $_children[] = [
                    $child['area_id'],
                    $child['area_name']
                ];
            }
            $buffer[] = "nc_a[$pid] = " . json_encode($_children,JSON_UNESCAPED_UNICODE) . ";";
            foreach ($children as $child) {
                $get_next_area($child['area_id']);
            }
        }
    };

    $get_next_area(0);

    file_put_contents($target,implode("\n",$buffer));


    echo 'success';

exit;